{include file="public/header" /}


<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>{$Think.lang.ds_statstore}</h3>
                <h5></h5>
            </div>
            {include file="public/admin_items" /}
        </div>
    </div>
   <div class="fixed-empty"></div>

  <form method="get"  name="formSearch" id="formSearch">
      <div class="ds-search-form">
            <dl>
                <dd>
                    <select name="search_sclass" id="search_sclass" class="querySelect">
                        <option value="" selected >{$Think.lang.ds_storeclass}</option>
                        {foreach name="store_class" item="v"}
                        <option value="{$v.storeclass_id}" {$Request.param.search_sclass == $v.storeclass_id ?'selected':''}>{$v.storeclass_name}</option>
                        {/foreach}
                    </select>
                </dd>
                <dd>
                    <select name="search_type" id="search_type" class="querySelect">
                        <option value="day" {$Request.param.search_type == 'day'?'selected':''}>{$Think.lang.search_type_day}</option>
                        <option value="week" {$Request.param.search_type == 'week'?'selected':''}>{$Think.lang.search_type_week}</option>
                        <option value="month" {$Request.param.search_type == 'month'?'selected':''}>{$Think.lang.search_type_month}</option>
                    </select>
                </dd>
                <dd id="searchtype_day" style="display:none;">
                    <input class="txt date" type="text" value="{:date('Y-m-d',$search_arr.day.search_time)}" id="search_time" name="search_time">
                </dd>
                <dd id="searchtype_week" style="display:none;">
                    <select name="searchweek_year" class="querySelect">
                        {foreach name="year_arr" item="v"}
                        <option value="{$key}" {if condition="$search_arr.week.current_year eq $key"}selected{/if}>{$v}</option>
                        {/foreach}
                    </select>
                    <select name="searchweek_month" class="querySelect">
                        {foreach name="month_arr" item="v"}
                        <option value="{$key}" {if condition="$search_arr.week.current_month eq $key"}selected{/if}>{$v}</option>
                        {/foreach}
                    </select>
                    <select name="searchweek_week" class="querySelect">
                        {foreach name="week_arr" item="v"}
                        <option value="{$v.key}" {if condition="$search_arr.week.current_week eq $v.key"}selected{/if}>{$v.val}</option>
                        {/foreach}
                    </select>
                </dd>
                <dd id="searchtype_month" style="display:none;">
                    <select name="searchmonth_year" class="querySelect">
                        {foreach name="year_arr" item="v"}
                        <option value="{$key}" {if condition="$search_arr.month.current_year eq $key"}selected{/if}>{$v}</option>
                        {/foreach}
                    </select>
                    <select name="searchmonth_month" class="querySelect">
                        {foreach name="month_arr" item="v"}
                        <option value="{$key}" {if condition="$search_arr.month.current_month eq $key"}selected{/if}>{$v}</option>
                        {/foreach}
                    </select>
                </dd>
            </dl>
			<dl>
                <dt>{$Think.lang.ds_store_name}</dt>
                <dd><input type="text" value="{$Request.get.search_sname}" name="search_sname" id="search_sname" class="txt"></dd>
            </dl>
            <div class="btn_group">
                <input type='text' style='display:none' name='t' value='{$searchtime}'>
                <a href="javascript:void(0);" id="dssubmit" class="btn tooltip" title="">{$Think.lang.ds_query}</a>
                <a href="{:url('Statstore/storesales')}" class="btn btn-default" title="{$Think.lang.ds_cancel}">{$Think.lang.ds_cancel}</a>
            </div>
        </div>
  </form>
   
 <div class="explanation" id="explanation">
        <div class="title" id="checkZoom">
            <h4 title="{$Think.lang.ds_explanation_tip}">{$Think.lang.ds_explanation}</h4>
            <span id="explanationZoom" title="{$Think.lang.ds_explanation_close}" class="arrow"></span>
        </div>
        <ul>
            <li>{$Think.lang.stat_validorder_explain}</li>
            <li>{$Think.lang.statstore_stat_store_sales_help1}</li>
            <li>{$Think.lang.statstore_stat_store_sales_help2}</li>
        </ul>
    </div>

  <div id="statlist" class="w100pre close_float ui-tabs"></div>
  <div id="stattrends" class="w100pre close_float ui-tabs"></div>
</div>

<script>
//展示搜索时间框
function show_searchtime(){
    s_type = $("#search_type").val();
    $("[id^='searchtype_']").hide();
    $("#searchtype_"+s_type).show();
}
//加载统计地图
function getTrends(storeid){
    $('#stattrends').load(ADMINSITEURL+'/Statstore/storesales_trends.html?storeid='+storeid+'&search_type='+s_type+'&t={$searchtime}');
}
$(function () {
    //统计数据类型
    var s_type = $("#search_type").val();
    $('#search_time').datepicker({dateFormat: 'yy-mm-dd'});

    show_searchtime();
    $("#search_type").change(function(){
        show_searchtime();
    });

    //更新周数组
    $("[name='searchweek_month']").change(function(){
        var year = $("[name='searchweek_year']").val();
        var month = $("[name='searchweek_month']").val();
        $("[name='searchweek_week']").html('');
        $.getJSON(ADMINSITEURL+'/Common/getweekofmonth',{y:year,m:month},function(data){
            if(data != null){
                for(var i = 0; i < data.length; i++) {
                    $("[name='searchweek_week']").append('<option value="'+data[i].key+'">'+data[i].val+'</option>');
                }
            }
        });
    });

    $('#dssubmit').click(function(){
        $('#formSearch').submit();
    });

    //加载统计列表
    //店铺分类
    var search_sclass = $("#search_sclass").val();
    var search_sname = $("#search_sname").val();
    $('#statlist').load(ADMINSITEURL+'/Statstore/storesales_list.html?search_sclass='+search_sclass+'&search_sname='+search_sname+'&t={$searchtime}');
    //店铺销售走势
    $("[ds_type='showtrends']").on('click',function(){
        var data_str = $(this).attr('data-param');
        eval('data_str = '+data_str);
        getTrends(data_str.storeid);
    });
});
</script>